<template>
    <div>
      <div class="hd">
        <span @click="$router.go(-1)"> 返回 </span>
        个人信息
      </div>
      <div style="padding:20px">
        <md-notice-bar >请务必输入正确的身份证账号和密码</md-notice-bar>
        <md-field>
          <md-input-item
            title="您的真实姓名"
            v-model="name"
            placeholder="请输入正确的姓名"
          ></md-input-item>

          <md-input-item
            title="手机号"
            type="phone"
            v-model="phone"
            placeholder="填写您的11位手机号码"
          ></md-input-item>

          <md-input-item
            title="身份证号码"
            v-model="idnum"
            placeholder="填写您的身份证号码"
          ></md-input-item>

        </md-field>

        <md-button @click="doupload"  v-if="!$store.state.wxuser.real_name && !$store.state.wxuser.phone && !$store.state.wxuser.id_num"  style="margin-top: 35px;">提交</md-button>

      </div>
    </div>
</template>

<script>
import { Toast } from 'mand-mobile'
export default {
  name: 'Userinfo',
  data () {
    return {
      idnum: '',
      phone: '',
      name: ''
    }
  },
  mounted: function () {
    this.idnum = this.$store.state.wxuser.id_num ? this.$store.state.wxuser.id_num : ''
    this.phone = this.$store.state.wxuser.phone ? this.$store.state.wxuser.phone : ''
    this.name = this.$store.state.wxuser.real_name ? this.$store.state.wxuser.real_name : ''
  },
  methods: {
    doupload: async function () {
      if (!this.idnum) {
        Toast.info('请提交正确的身份证号码')
        return false
      }
      if (!this.phone) {
        Toast.info('请提交正确的手机号码')
        return false
      }
      if (!this.name) {
        Toast.info('真实姓名不能为空')
        return false
      }
      let _res = await this.$api.post('/verifyUser', {
        real_name: this.name,
        phone: this.phone,
        id_num: this.idnum,
        uid: this.$store.state.wxuser.uid ? this.$store.state.wxuser.uid : 1
      })
      if (_res.data.state) {
        Toast.succeed('提交成功')
        this.$store.dispatch('getUser')
        this.$router.history.go(-1)
      } else {
        Toast.failed('提交失败' + _res.data.info ? `( ${_res.data.info})` : '')
      }
    }

  }
}
</script>

<style scoped>

</style>
